package com.icim.xmtm005.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.icim.util.GUIDGenerator;
import com.icim.xmtm005.entity.CtSlimifRetDefectData005;

@Repository
public class CtSlimifRetDefectData005Dao {
	@Resource
	private JdbcTemplate xmtm005JdbcTemplate;

	public void saveBatch(List<CtSlimifRetDefectData005> defectList) {
		List<Object[]> objsList = new ArrayList<Object[]>();
//		String sql = "INSERT INTO CT_SLIMIFRETDEFECTDATA"
		String sql = "INSERT INTO V_XM_G5_SLIMIFRETDEFECTDATA_WG"
				+ "("
				+ "UNIQUESEQUENCEID,VENDORCODE,PRODUCTNAME,DEFECTTYPE,DEFECTPOSITION,DEFECTSIDE,"
				+ "INSPECTOPERATION,INSPECTUSER,INSPECTTIME,DEFECTCODE,DEFECTXYAXIS"
				+ ",DEFECTDESCRIPTION" + ")"
				+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";

		for (CtSlimifRetDefectData005 defect : defectList) {

			objsList.add(new Object[] { GUIDGenerator.javaGUID(),
					defect.getVendorcode(), defect.getProductname(),
					defect.getDefecttype(), defect.getDefectposition(),
					defect.getDefectside(), defect.getInspectoperation(),
					defect.getInspectuser(), defect.getInspecttime(),
					defect.getDefectcode(), defect.getDefectxyaxis(),
					defect.getDefectdescription() });
		}

		xmtm005JdbcTemplate.batchUpdate(sql, objsList);
	}

	public void save(CtSlimifRetDefectData005 defect) {
//		String sql = "INSERT INTO CT_SLIMIFRETDEFECTDATA"
		String sql = "INSERT INTO V_XM_G5_SLIMIFRETDEFECTDATA_WG"
				+ "("
				+ "UNIQUESEQUENCEID,VENDORCODE,PRODUCTNAME,DEFECTTYPE,DEFECTPOSITION,DEFECTSIDE,"
				+ "INSPECTOPERATION,INSPECTUSER,INSPECTTIME,DEFECTCODE,DEFECTXYAXIS"
				+ ",DEFECTDESCRIPTION" + ")"
				+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";

		Object[] args = new Object[] { GUIDGenerator.javaGUID(),
				defect.getVendorcode(), defect.getProductname(),
				defect.getDefecttype(), defect.getDefectposition(),
				defect.getDefectside(), defect.getInspectoperation(),
				defect.getInspectuser(), defect.getInspecttime(),
				defect.getDefectcode(), defect.getDefectxyaxis(),
				defect.getDefectdescription() };

		xmtm005JdbcTemplate.update(sql, args);
	}
}
